package com.zang.test;

import com.google.protobuf.InvalidProtocolBufferException;
import com.zang.netty.model.pojo.UserInfo;
import com.zang.protobuf.proto.SubscribeReqProto;
import redis.clients.jedis.Jedis;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

/**
 * 测试序列化之后和二进制对比
 * @author Zhang Qiang
 * @Date 2019/7/22 8:56
 */
public class Action {

    public static void main(String[] args) throws IOException {

        testBuild();

    }


     /**
      * java原生
      */
    private static void testJdk() throws IOException {
        UserInfo info = UserInfo.builder().id(5).name("Welcome to Netty").build();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bos);
        os.writeObject(info);
        os.flush();
        os.close();
        byte[] b = bos.toByteArray();
        System.out.println("The jdk serializable length is :" + b.length);
        bos.close();
        System.out.println("UserInfo byte array serializable length is ： " + info.codeC().length);
    }
    private static void testBuild() throws InvalidProtocolBufferException {
        SubscribeReqProto.SubscribeReq.Builder reqBuilder = SubscribeReqProto.SubscribeReq.newBuilder();
        SubscribeReqProto.SubscribeReq.Builder reqB2 = SubscribeReqProto.SubscribeReq.newBuilder();

        reqBuilder.setSubReqId(5);
        reqBuilder.setAddress("广州");

        byte[] b = reqBuilder.build().toByteArray();
        System.out.println( "reqBuilder length:" + b.length);

        reqB2.mergeFrom(b);
        System.out.println("reqB2 : " + reqB2.getAddress());

    }

    private static Jedis jredis(){
        String txHost = "94.191.22.242";
        int port = 6379;
        Jedis jedis = new Jedis(txHost, port);
        jedis.auth("adminZhang");

        System.out.println( "jedis test:" + jedis.ping());
        return jedis;
    }


}
